<%@ page import="java.util.Arrays" %>
<%@ page import="cn.cjxy.domain.Student" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 12460
  Date: 2024/11/30
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>foreach遍历</title>
    <style>
        table {
            width: 500px;
            border-collapse: collapse;
        }
        tr {
            height: 35px;
        }
        td {
            text-align: center;
        }
    </style>
</head>
<body>
       <h2>遍历集合</h2>
        <%
            //添加学生集合
            List<Student> studentList = Arrays.asList(
                    new Student(63, "张三", '1', 90),
                    new Student(64, "李四", '1', 98),
                    new Student(65, "王五", '0', 92),
                    new Student(66, "小红", '0', 88)
            );

            //放入作用域
            request.setAttribute("stuList",studentList);
        %>
        <table border="1">
            <caption>学生信息表</caption>
            <tr>
                <th>序号</th>
                <th>学号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>成绩</th>
            </tr>
            <%--
            items:表示要遍历的集合，要使用EL
            var：变量名，表示集合中的每个元素对象
            varStatus:表示一个对象名字，当前的行对象
            --%>
            <c:forEach items="${stuList}" var="stu" varStatus="row">
                <tr>
                    <td>${row.index+1}</td>
                    <td>${stu.id}</td>
                    <td>${stu.name}</td>
                    <td>${stu.gender}</td>
                    <td>${stu.score}</td>
                </tr>

            </c:forEach>

        </table>

</body>
</html>
